/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.meanzoft.minecraft_clone.effect;

import org.lwjgl.util.vector.Vector4f;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import static org.lwjgl.opengl.GL11.*;

/**
 *
 * @author Meanz
 */
public class Light {

    /**
     * Lights
     */
    private static final int[] lights = {GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, GL_LIGHT3, GL_LIGHT4, GL_LIGHT5, GL_LIGHT6, GL_LIGHT7};
    private boolean enabled;
    private int lightId;

    public Light(int lightId) {
        if (lightId > 7) {
            lightId = 7;
        }
        this.lightId = lightId;
    }

    public void enable() {
        update();
        glEnable(lights[lightId]);
        enabled = true;
    }

    public void disable() {
        glDisable(lights[lightId]);
        enabled = false;
    }

    public void update() {
    }

    public void setParams(int cap, Vector4f values) {
        ByteBuffer bb = ByteBuffer.allocateDirect(16);
        bb.order(ByteOrder.nativeOrder());
        bb.putFloat(values.x);
        bb.putFloat(values.y);
        bb.putFloat(values.z);
        bb.putFloat(values.w);
        bb.flip();
        glLight(lights[lightId], cap, bb.asFloatBuffer());             // Setup The Ambient Light

    }

    public boolean isEnabled() {
        return enabled;
    }
}
